#define  _CRT_SECURE_NO_WARNINGS
class Solution {
    int hammingWeight(int n) {
        int count = 0;
        while (n) count++, n &= (n - 1);
        return count;
    }
public:
    vector<int> countBits(int n) {
        vector<int> ret(n + 1);
        for (int i = 0; i <= n; i++) ret[i] = hammingWeight(i);
        return ret;
    }
};